/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package workingsafe;

import ca.odell.glazedlists.GlazedLists;
import ca.odell.glazedlists.swing.AutoCompleteSupport;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;

/**
 *
 * @author d015532
 */
public class SGAR extends javax.swing.JFrame {

    /**
     * Creates new form SGAR
     */
    DefaultListModel modeloLista = new DefaultListModel();
    
    ArrayList<String> impactoInvolucradosAcc;
    
    AutoCompleteSupport support;
    
    public SGAR() throws IOException {
        initComponents();
        lstFactoresRiesgo.setModel(modeloLista);
        formAgregarFactoresRiesgo.setVisible(false);
        formAgregarFactoresRiesgo.setIconifiable(true);
        formSeleccionarArea.setVisible(false);
        //formAgregarFactoresRiesgo.setMaximizable(true);
        cboNivelCapacitacion.setModel(new javax.swing.DefaultComboBoxModel(sistema.getListaNivelCapacitacion().toArray()));
        actualizarCboFactorRiesgo();
        cargarCboAreaRiesgos();
        cboImpacto.setModel(new javax.swing.DefaultComboBoxModel(sistema.getListaImpactosAccidente().toArray()));
        impactoInvolucradosAcc = new ArrayList<String>();
        
        cboEdificio.setModel(new javax.swing.DefaultComboBoxModel(sistema.getListaEdificios().toArray()));
        cboPlanta.setModel(new javax.swing.DefaultComboBoxModel(sistema.getListaPlantas().toArray()));
        cboSector.setModel(new javax.swing.DefaultComboBoxModel(sistema.getListaSectores().toArray()));
        cboOrientacion.setModel(new javax.swing.DefaultComboBoxModel(sistema.getListaOrientacion().toArray()));
        
        jButton1.setIcon(new ImageIcon(ImageIO.read( new File("iconos\\crear_poligono2.png"))));
        //jButton1.setIcon(new ImageIcon(getClass().getResource("iconos\\crear_poligono2.png")));
//        btnConfirmarImpacto.setIcon(new ImageIcon(getClass().getResource("iconos\\Icono_Accidente.png")));
//        btnGuardarAreaRiesgo.setIcon(new ImageIcon(getClass().getResource("iconos\\Guardar.png")));
//        btnCancelarAltaAreaRiesgo.setIcon(new ImageIcon(getClass().getResource("iconos\\Cancelar.png")));
        btnConfirmarImpacto.setIcon(new ImageIcon(ImageIO.read( new File("iconos\\Icono_Accidente.png"))));
        btnGuardarAreaRiesgo.setIcon(new ImageIcon(ImageIO.read( new File("iconos\\Guardar.png"))));
        btnCancelarAltaAreaRiesgo.setIcon(new ImageIcon(ImageIO.read( new File("iconos\\Cancelar.png"))));
        
    }
    
    private void actualizarCboFactorRiesgo(){
        ArrayList<String> listaIdsFactores = sistema.ObtenerIdsFactoresDeRiesgo();
        ArrayList<String> listaNombresFactores = sistema.ObtenerNombresFactoresDeRiesgo();
        listaIdsFactores.addAll(listaNombresFactores);
        AutoCompleteSupport support = AutoCompleteSupport.install(cboFactorDeRiesgo, GlazedLists.eventListOf(listaIdsFactores.toArray())); 
        cboFactorDeRiesgo.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() 
        {
            public void keyPressed(KeyEvent evt)
            {
                if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB)
                {
                    controlEventosCboFactorDeRiesgo();
                }
            }
        });
        
//        cboFactorDeRiesgo.getEditor().getEditorComponent().addFocusListener(new FocusListener()
//        {
//            @Override
//            public void focusGained(FocusEvent arg0) 
//            {
//                controlEventosCboFactorDeRiesgo();
//            }
//            
//            @Override
//            public void focusLost(FocusEvent arg0) {
//                
//            }
//        });
    }
    
    private void controlEventosCboFactorDeRiesgo(){
        
        if (cboFactorDeRiesgo.getSelectedItem() != null){
                    String factor = cboFactorDeRiesgo.getSelectedItem().toString();
                    if (sistema.ExisteIdFactorRiesgo(factor)){
                        txtAreaDescr.setText(sistema.ObtenerFactorDeRiesgoDesdeId(factor).getDescrFactor());
                        JOptionPane.showMessageDialog(null, "Factor:"+factor+"     "+sistema.ObtenerFactorDeRiesgoDesdeId(factor).getDescrFactor(),"Informacion",JOptionPane.INFORMATION_MESSAGE);
                        
                    }
                    else if (sistema.ExisteNombreFactorRiesgo(factor)){
                        txtAreaDescr.setText(sistema.ObtenerFactorDeRiesgoDesdeNombre(factor).getDescrFactor());
                        JOptionPane.showMessageDialog(null, sistema.ObtenerFactorDeRiesgoDesdeNombre(factor).getDescrFactor(),"Informacion",JOptionPane.INFORMATION_MESSAGE);
                    }
                    else {
                        JOptionPane.showMessageDialog(null, "No existe el factor de riesgo seleccionado","Atencion",JOptionPane.WARNING_MESSAGE);
                    }
            
        }
                    
    }
    
    private void cargarCboAreaRiesgos(){
        ArrayList<String> listaIdsAreas = sistema.ObtenerIdsAreasDeRiesgo();
        ArrayList<String> listaNombresAreas = sistema.ObtenerNombresAreasDeRiesgo();
        listaIdsAreas.addAll(listaNombresAreas);        
        support = AutoCompleteSupport.install(cboAreaRiesgo, GlazedLists.eventListOf(listaIdsAreas.toArray()));        
                
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        panelAltaAreaRiesgo = new javax.swing.JPanel();
        lblIdArea = new javax.swing.JLabel();
        txtIdArea = new javax.swing.JTextField();
        lblNombreArea = new javax.swing.JLabel();
        txtNombreArea = new javax.swing.JTextField();
        btnAgregarFactorRiesgo = new javax.swing.JButton();
        lblNivelCapacitacion = new javax.swing.JLabel();
        cboNivelCapacitacion = new javax.swing.JComboBox();
        btnGuardarAreaRiesgo = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        formAgregarFactoresRiesgo = new javax.swing.JInternalFrame();
        panelDescrFactor = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAreaDescr = new javax.swing.JTextArea();
        btnAgregarF = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstFactoresRiesgo = new javax.swing.JList();
        lblFactorDeRiesgo = new javax.swing.JLabel();
        cboFactorDeRiesgo = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        formSeleccionarArea = new javax.swing.JInternalFrame();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cboEdificio = new javax.swing.JComboBox();
        cboPlanta = new javax.swing.JComboBox();
        cboSector = new javax.swing.JComboBox();
        cboOrientacion = new javax.swing.JComboBox();
        btnAgregarArea = new javax.swing.JButton();
        btnCancelarAltaAreaRiesgo = new javax.swing.JButton();
        panelAltaAccidente = new javax.swing.JPanel();
        txtIdAccidente = new javax.swing.JTextField();
        lblIdAccidente = new javax.swing.JLabel();
        lblAreaRiesgo = new javax.swing.JLabel();
        cboAreaRiesgo = new javax.swing.JComboBox();
        ftxtFechaAccidente = new javax.swing.JFormattedTextField();
        lblFechaAccidente = new javax.swing.JLabel();
        lblHoraAccidente = new javax.swing.JLabel();
        ftxtHoraAccidente = new javax.swing.JFormattedTextField();
        btnGuardarAccidente = new javax.swing.JButton();
        jpInvolucrados = new javax.swing.JPanel();
        lblInvolucrados = new javax.swing.JLabel();
        lblImpacto = new javax.swing.JLabel();
        cboImpacto = new javax.swing.JComboBox();
        btnConfirmarImpacto = new javax.swing.JButton();
        lblTotalInvolucrados = new javax.swing.JLabel();
        txtTotalInvolucrados = new javax.swing.JTextField();
        jSpinner2 = new javax.swing.JSpinner();
        lblHS = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema de Gestión de Áreas de Riesgo");
        getContentPane().setLayout(null);

        lblIdArea.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblIdArea.setText("ID Area");

        txtIdArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdAreaActionPerformed(evt);
            }
        });

        lblNombreArea.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblNombreArea.setText("Nombre de Area");

        btnAgregarFactorRiesgo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAgregarFactorRiesgo.setText("Agregar Factor de Riesgo");
        btnAgregarFactorRiesgo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarFactorRiesgoActionPerformed(evt);
            }
        });

        lblNivelCapacitacion.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblNivelCapacitacion.setText("Nivel de Capacitacion");

        cboNivelCapacitacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboNivelCapacitacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboNivelCapacitacionActionPerformed(evt);
            }
        });

        btnGuardarAreaRiesgo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnGuardarAreaRiesgo.setText("Guardar Area de Riesgo");
        btnGuardarAreaRiesgo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarAreaRiesgoActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton1.setText("Definir área de riesgo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        formAgregarFactoresRiesgo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        formAgregarFactoresRiesgo.setClosable(true);
        formAgregarFactoresRiesgo.setTitle("Agregar Factor de Riesgo");
        formAgregarFactoresRiesgo.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        formAgregarFactoresRiesgo.setVisible(true);
        formAgregarFactoresRiesgo.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
                formAgregarFactoresRiesgoInternalFrameIconified(evt);
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        panelDescrFactor.setBorder(javax.swing.BorderFactory.createTitledBorder("Descripcion"));
        panelDescrFactor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        txtAreaDescr.setColumns(20);
        txtAreaDescr.setRows(5);
        txtAreaDescr.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        txtAreaDescr.setEnabled(false);
        jScrollPane2.setViewportView(txtAreaDescr);

        javax.swing.GroupLayout panelDescrFactorLayout = new javax.swing.GroupLayout(panelDescrFactor);
        panelDescrFactor.setLayout(panelDescrFactorLayout);
        panelDescrFactorLayout.setHorizontalGroup(
            panelDescrFactorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        panelDescrFactorLayout.setVerticalGroup(
            panelDescrFactorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDescrFactorLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        btnAgregarF.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAgregarF.setText("Agregar");
        btnAgregarF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarFActionPerformed(evt);
            }
        });

        lstFactoresRiesgo.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(lstFactoresRiesgo);

        lblFactorDeRiesgo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblFactorDeRiesgo.setText("Escriba Factor de Riesgo");

        cboFactorDeRiesgo.setEditable(true);
        cboFactorDeRiesgo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Factores agregados");

        javax.swing.GroupLayout formAgregarFactoresRiesgoLayout = new javax.swing.GroupLayout(formAgregarFactoresRiesgo.getContentPane());
        formAgregarFactoresRiesgo.getContentPane().setLayout(formAgregarFactoresRiesgoLayout);
        formAgregarFactoresRiesgoLayout.setHorizontalGroup(
            formAgregarFactoresRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(formAgregarFactoresRiesgoLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(formAgregarFactoresRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(formAgregarFactoresRiesgoLayout.createSequentialGroup()
                        .addComponent(lblFactorDeRiesgo)
                        .addGap(59, 59, 59)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(formAgregarFactoresRiesgoLayout.createSequentialGroup()
                        .addGroup(formAgregarFactoresRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cboFactorDeRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(panelDescrFactor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnAgregarF, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        formAgregarFactoresRiesgoLayout.setVerticalGroup(
            formAgregarFactoresRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(formAgregarFactoresRiesgoLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(formAgregarFactoresRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFactorDeRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(formAgregarFactoresRiesgoLayout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabel1)))
                .addGap(7, 7, 7)
                .addGroup(formAgregarFactoresRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(formAgregarFactoresRiesgoLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(cboFactorDeRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(panelDescrFactor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(btnAgregarF)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        formSeleccionarArea.setClosable(true);
        formSeleccionarArea.setTitle("Seleccion de areas predifinidas");
        formSeleccionarArea.setVisible(true);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Edificio");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Planta");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("Sector");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Orientacion");

        cboEdificio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cboPlanta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cboSector.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cboOrientacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnAgregarArea.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAgregarArea.setText("Agregar Area");
        btnAgregarArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarAreaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout formSeleccionarAreaLayout = new javax.swing.GroupLayout(formSeleccionarArea.getContentPane());
        formSeleccionarArea.getContentPane().setLayout(formSeleccionarAreaLayout);
        formSeleccionarAreaLayout.setHorizontalGroup(
            formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(formSeleccionarAreaLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(formSeleccionarAreaLayout.createSequentialGroup()
                        .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(formSeleccionarAreaLayout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cboOrientacion, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(btnAgregarArea, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(20, Short.MAX_VALUE))
                    .addGroup(formSeleccionarAreaLayout.createSequentialGroup()
                        .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(39, 39, 39)
                        .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(cboPlanta, 0, 130, Short.MAX_VALUE)
                                .addComponent(cboSector, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(cboEdificio, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        formSeleccionarAreaLayout.setVerticalGroup(
            formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(formSeleccionarAreaLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cboEdificio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cboPlanta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cboSector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(26, 26, 26)
                .addGroup(formSeleccionarAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cboOrientacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addComponent(btnAgregarArea)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        btnCancelarAltaAreaRiesgo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnCancelarAltaAreaRiesgo.setText("Cancelar Alta");
        btnCancelarAltaAreaRiesgo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarAltaAreaRiesgoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelAltaAreaRiesgoLayout = new javax.swing.GroupLayout(panelAltaAreaRiesgo);
        panelAltaAreaRiesgo.setLayout(panelAltaAreaRiesgoLayout);
        panelAltaAreaRiesgoLayout.setHorizontalGroup(
            panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(lblIdArea)
                        .addGap(18, 18, 18)
                        .addComponent(txtIdArea, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblNombreArea)
                        .addGap(10, 10, 10)
                        .addComponent(txtNombreArea, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(lblNivelCapacitacion)
                        .addGap(28, 28, 28)
                        .addComponent(cboNivelCapacitacion, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                                .addComponent(formSeleccionarArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(formAgregarFactoresRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                                .addComponent(btnGuardarAreaRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelarAltaAreaRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(btnAgregarFactorRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelAltaAreaRiesgoLayout.setVerticalGroup(
            panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtIdArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNombreArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblIdArea)
                            .addComponent(lblNombreArea))))
                .addGap(25, 25, 25)
                .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNivelCapacitacion)
                    .addComponent(cboNivelCapacitacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAgregarFactorRiesgo)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addComponent(formSeleccionarArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAltaAreaRiesgoLayout.createSequentialGroup()
                        .addComponent(formAgregarFactoresRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)))
                .addGroup(panelAltaAreaRiesgoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardarAreaRiesgo)
                    .addComponent(btnCancelarAltaAreaRiesgo))
                .addContainerGap(66, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Alta área de riesgo", panelAltaAreaRiesgo);

        txtIdAccidente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdAccidenteActionPerformed(evt);
            }
        });
        txtIdAccidente.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtIdAccidenteFocusLost(evt);
            }
        });

        lblIdAccidente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblIdAccidente.setText("Id Accidente");

        lblAreaRiesgo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblAreaRiesgo.setText("Escriba Area de Riesgo");

        cboAreaRiesgo.setEditable(true);
        cboAreaRiesgo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        try {
            ftxtFechaAccidente.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        lblFechaAccidente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblFechaAccidente.setText("Fecha accidente");

        lblHoraAccidente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblHoraAccidente.setText("Hora accidente");

        try {
            ftxtHoraAccidente.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        btnGuardarAccidente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnGuardarAccidente.setText("Guardar Reporte de Accidente");
        btnGuardarAccidente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarAccidenteActionPerformed(evt);
            }
        });

        jpInvolucrados.setBorder(javax.swing.BorderFactory.createTitledBorder("Impacto sufrido en involucrados"));

        lblInvolucrados.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblInvolucrados.setText("Involucrado Nro.");

        lblImpacto.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblImpacto.setText("Impacto");

        cboImpacto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btnConfirmarImpacto.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnConfirmarImpacto.setText("Confirmar impacto por involucrado");
        btnConfirmarImpacto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarImpactoActionPerformed(evt);
            }
        });

        lblTotalInvolucrados.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lblTotalInvolucrados.setText("Total de Involucrados");

        txtTotalInvolucrados.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtTotalInvolucradosFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jpInvolucradosLayout = new javax.swing.GroupLayout(jpInvolucrados);
        jpInvolucrados.setLayout(jpInvolucradosLayout);
        jpInvolucradosLayout.setHorizontalGroup(
            jpInvolucradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpInvolucradosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpInvolucradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpInvolucradosLayout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(btnConfirmarImpacto, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpInvolucradosLayout.createSequentialGroup()
                        .addComponent(lblTotalInvolucrados)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtTotalInvolucrados, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpInvolucradosLayout.createSequentialGroup()
                        .addComponent(lblInvolucrados)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblImpacto)
                        .addGap(18, 18, 18)
                        .addComponent(cboImpacto, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jpInvolucradosLayout.setVerticalGroup(
            jpInvolucradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpInvolucradosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpInvolucradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTotalInvolucrados)
                    .addComponent(txtTotalInvolucrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addGroup(jpInvolucradosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblInvolucrados)
                    .addComponent(lblImpacto)
                    .addComponent(cboImpacto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnConfirmarImpacto)
                .addGap(23, 23, 23))
        );

        lblHS.setText("hs");

        javax.swing.GroupLayout panelAltaAccidenteLayout = new javax.swing.GroupLayout(panelAltaAccidente);
        panelAltaAccidente.setLayout(panelAltaAccidenteLayout);
        panelAltaAccidenteLayout.setHorizontalGroup(
            panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                                .addComponent(lblFechaAccidente)
                                .addGap(20, 20, 20)
                                .addComponent(ftxtFechaAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(37, 37, 37)
                                .addComponent(lblHoraAccidente)
                                .addGap(18, 18, 18)
                                .addComponent(ftxtHoraAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblHS))
                            .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                                .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblAreaRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblIdAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(10, 10, 10)
                                .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtIdAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cboAreaRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(btnGuardarAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jpInvolucrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(163, Short.MAX_VALUE))
        );
        panelAltaAccidenteLayout.setVerticalGroup(
            panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAltaAccidenteLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtIdAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblIdAccidente))
                .addGap(20, 20, 20)
                .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAreaRiesgo)
                    .addComponent(cboAreaRiesgo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(panelAltaAccidenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblHoraAccidente)
                    .addComponent(ftxtHoraAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftxtFechaAccidente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFechaAccidente)
                    .addComponent(lblHS))
                .addGap(20, 20, 20)
                .addComponent(jpInvolucrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnGuardarAccidente)
                .addGap(197, 197, 197))
        );

        jTabbedPane1.addTab("Alta de accidente", panelAltaAccidente);

        getContentPane().add(jTabbedPane1);
        jTabbedPane1.setBounds(0, 0, 665, 584);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-531)/2, (screenSize.height-627)/2, 531, 627);
    }// </editor-fold>//GEN-END:initComponents

    private void txtIdAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdAreaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdAreaActionPerformed

    private void cboNivelCapacitacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboNivelCapacitacionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboNivelCapacitacionActionPerformed

    private void btnAgregarFactorRiesgoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarFactorRiesgoActionPerformed
        // TODO add your handling code here:
        formAgregarFactoresRiesgo.setVisible(true);
    }//GEN-LAST:event_btnAgregarFactorRiesgoActionPerformed

    private void limpiarAltaAreaDeRiesgo() {
        txtIdArea.setText("");
        txtNombreArea.setText("");
        cboNivelCapacitacion.setSelectedIndex(0);
        modeloLista.removeAllElements();
        
    }
    
    private void btnGuardarAreaRiesgoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarAreaRiesgoActionPerformed
        // TODO add your handling code here:
        String factores = "";
        for (int i = 0; i < lstFactoresRiesgo.getModel().getSize(); i++) {
            String item = lstFactoresRiesgo.getModel().getElementAt(i).toString();
            factores = factores + item + "#";
        }
        String idArea = txtIdArea.getText();
        String nombreArea = txtNombreArea.getText();
        String nivelCapacit = cboNivelCapacitacion.getSelectedItem().toString();
        boolean controlCamposOK = !idArea.equals("") && !nombreArea.equals("");
        if (controlCamposOK){
            if (sistema.getCoordenadasAreaRiesgo().isEmpty()){
                JOptionPane.showMessageDialog(null, "Debe delimitar antes el area de riesgo","Atencion",JOptionPane.INFORMATION_MESSAGE);
            }
            else{
               if (sistema.ExisteIdAreaRiesgo(idArea)){
                    int seleccion = JOptionPane.showConfirmDialog(null, "Existe un Área de Riesgo con el mismo identificador \n¿Desea guardar este Área de Riesgo con otro identificador?", "Atención", JOptionPane.YES_NO_OPTION);
                    if(seleccion == JOptionPane.YES_OPTION){
                        idArea = (String)JOptionPane.showInputDialog(null,"Escriba un nuevo ID:\n","Ingreso de ID",JOptionPane.PLAIN_MESSAGE,null,null,"ID");                
                        txtIdArea.setText(idArea);
                    }
                }
                else if (sistema.ExisteNombreAreaRiesgo(nombreArea)){
                        int seleccion = JOptionPane.showConfirmDialog(null, "Existe un Área de Riesgo con el mismo nombre \n¿Desea guardar este Área de Riesgo con otro nombre?", "Atención", JOptionPane.YES_NO_OPTION);
                        if(seleccion == JOptionPane.YES_OPTION){
                            nombreArea = (String)JOptionPane.showInputDialog(null,"Escriba un nuevo nombre:\n","Ingreso de nombre",JOptionPane.PLAIN_MESSAGE,null,null,"nombre");                
                            txtNombreArea.setText(nombreArea);
                        }
                }        
                else if (sistema.isAreaPorGeoloc() && sistema.getCoordenadasAreaRiesgo().size()<3){            
                        int seleccion = JOptionPane.showConfirmDialog(null, "Los puntos seleccionados no definen un area cerrada ¿Desea continuar?", "Atención", JOptionPane.YES_NO_OPTION);
                        if(seleccion == JOptionPane.YES_OPTION){
                            sistema.GuardarAreaRiesgo(idArea, nombreArea, nivelCapacit, factores);
                            sistema.vaciarCoordenadasAreaRiesgo();
                            support.getItemList().add(idArea);
                            support.getItemList().add(nombreArea);
        
                            limpiarAltaAreaDeRiesgo();
                            JOptionPane.showMessageDialog(null, "Se guardo el area de riesgo " +nombreArea+" satisfactoriamente","Informacion",JOptionPane.INFORMATION_MESSAGE);
                        }
                    }
                else{
                    sistema.GuardarAreaRiesgo(idArea, nombreArea, nivelCapacit, factores);
                    sistema.vaciarCoordenadasAreaRiesgo();
                    support.getItemList().add(idArea);
                    support.getItemList().add(nombreArea);
                    limpiarAltaAreaDeRiesgo();
                    JOptionPane.showMessageDialog(null, "Se guardo el area de riesgo " +nombreArea+" satisfactoriamente","Informacion",JOptionPane.INFORMATION_MESSAGE);
                } 
            }
        }
        else{
            JOptionPane.showMessageDialog(null, "Debe ingresar un Identificador y Nombre del Area de Riesgo","Atencion",JOptionPane.WARNING_MESSAGE);
        }
        
        
    }//GEN-LAST:event_btnGuardarAreaRiesgoActionPerformed

    private void txtIdAccidenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdAccidenteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdAccidenteActionPerformed

    private void txtIdAccidenteFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtIdAccidenteFocusLost
        // TODO add your handling code here:
        String idAcc = txtIdAccidente.getText();
        // tengo que crear el metodo cargarAccidentes en manejode archivos
        //obteneraccidentes y existeAccidente en sistema
        //despues si el id no existe sigo, si existe pregunto si desea guaardar con otro id... y mas
    }//GEN-LAST:event_txtIdAccidenteFocusLost

    private void btnGuardarAccidenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarAccidenteActionPerformed
        // TODO add your handling code here:
        String idAcc = txtIdAccidente.getText();
        String areaRiesgo = "";
        if (cboAreaRiesgo.getSelectedItem() != null){
            areaRiesgo = cboAreaRiesgo.getSelectedItem().toString();
        }
        String fecha = ftxtFechaAccidente.getText();
        String hora = ftxtHoraAccidente.getText();
        String totalInvoluc = txtTotalInvolucrados.getText();
        boolean controlCamposOK = !idAcc.equals("") && !areaRiesgo.equals("") && !fecha.equals("") && !hora.equals("")
                && !totalInvoluc.equals("");
        if (controlCamposOK){
            if (impactoInvolucradosAcc.size() < Integer.parseInt(totalInvoluc)){
                JOptionPane.showMessageDialog(null, "Falto ingresar impacto para algun/os involucrados","Atencion",JOptionPane.INFORMATION_MESSAGE);
            }
            else{
               if (sistema.ExisteAccidente(idAcc)){
                   int seleccion = JOptionPane.showConfirmDialog(null, "Existe un Accidente registrado con el mismo identificador \n¿Desea guardar este Accidente con otro identificador?", "Atención", JOptionPane.YES_NO_OPTION);
                    if(seleccion == JOptionPane.YES_OPTION){
                        idAcc = (String)JOptionPane.showInputDialog(null,"Escriba un nuevo ID:\n","Ingreso de ID",JOptionPane.PLAIN_MESSAGE,null,null,"ID");                
                        txtIdAccidente.setText(idAcc);
                    }
               }
               else if (!sistema.ExisteIdAreaRiesgo(areaRiesgo) && !sistema.ExisteNombreAreaRiesgo(areaRiesgo)){
                   int seleccion = JOptionPane.showConfirmDialog(null, "No existe el Área de Riesgo solicitado \n¿Desea crearlo?", "Atención", JOptionPane.YES_NO_OPTION);
                    if(seleccion == JOptionPane.YES_OPTION){
                        jTabbedPane1.setSelectedIndex(0);
                    }
               }
               else{
                   sistema.GuardarAccidente(idAcc, areaRiesgo, fecha, hora, totalInvoluc, impactoInvolucradosAcc);
                    impactoInvolucradosAcc = new ArrayList<String>();
                    txtIdAccidente.setText("");
                    cboAreaRiesgo.setSelectedItem("");
                    ftxtFechaAccidente.setText("");
                    ftxtHoraAccidente.setText("");
                    txtTotalInvolucrados.setText("");
                    
                    jSpinner2.setValue(1);
                    cboImpacto.setSelectedIndex(0);
                    JOptionPane.showMessageDialog(null, "Registro guardado correctamente","Informacion",JOptionPane.INFORMATION_MESSAGE);
               }
            }
            
        }
        else{
            JOptionPane.showMessageDialog(null, "Quedaron campos sin completar.","Atencion",JOptionPane.WARNING_MESSAGE);
        }
        
    }//GEN-LAST:event_btnGuardarAccidenteActionPerformed

    private void btnConfirmarImpactoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarImpactoActionPerformed
        // TODO add your handling code here:    
        
        int valor = Integer.parseInt(jSpinner2.getModel().getValue().toString());
        int total = Integer.parseInt(txtTotalInvolucrados.getText());
        if (valor <= total){
            impactoInvolucradosAcc.add(cboImpacto.getSelectedItem().toString());
            if (valor == total){
                JOptionPane.showMessageDialog(null, "Se cargaron todos los impactados correctamente.","Informacion",JOptionPane.INFORMATION_MESSAGE);
                btnConfirmarImpacto.setEnabled(false);
            }
            else{
                int proxValor = valor+1;
                jSpinner2.setValue(proxValor);
            }
        }
    }//GEN-LAST:event_btnConfirmarImpactoActionPerformed

    private void formAgregarFactoresRiesgoInternalFrameIconified(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formAgregarFactoresRiesgoInternalFrameIconified
        //        try {
            // TODO add your handling code here:
            //JOptionPane.showMessageDialog(null, "Ventana minimizada","Informacion",JOptionPane.INFORMATION_MESSAGE);
            formAgregarFactoresRiesgo.setSize(347, 25);
            //formAgregarFactoresRiesgo.setIcon(true);
            //        } catch (PropertyVetoException ex) {
            //            Logger.getLogger(SGAR.class.getName()).log(Level.SEVERE, null, ex);
            //        }
    }//GEN-LAST:event_formAgregarFactoresRiesgoInternalFrameIconified

    private void btnAgregarFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarFActionPerformed
        // TODO add your handling code here:
        String factor = cboFactorDeRiesgo.getSelectedItem().toString(); 
        if (sistema.ExisteIdFactorRiesgo(factor) || sistema.ExisteNombreFactorRiesgo(factor)){
            int seleccion = JOptionPane.showConfirmDialog(null, "¿Este factor de riesgo es monitoreado?", "Atención", JOptionPane.YES_NO_OPTION);
            if(seleccion == JOptionPane.YES_OPTION){
                modeloLista.addElement(factor+"-ConMon");
            }
            else {
                modeloLista.addElement(factor+"-SinMon");
            }
        }
        else{
            JOptionPane.showMessageDialog(null, "No existe el factor de riesgo que quiere agregar","Atencion",JOptionPane.WARNING_MESSAGE);
            
        }
        cboFactorDeRiesgo.setSelectedItem("");
    }//GEN-LAST:event_btnAgregarFActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        int seleccion = JOptionPane.showOptionDialog(null, "Seleccione opcion","Delimitar Area",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,  new Object[] { "Por Geolocalizacion", "Areas Predifinidas"}, "Por Geolocalizacion");
 
        if (seleccion == 0){            
            VentanaDelimitarAera vent = null;
            try {
                vent = new VentanaDelimitarAera(sistema);
            } catch (IOException ex) {
                Logger.getLogger(SGAR.class.getName()).log(Level.SEVERE, null, ex);
            }
            vent.setVisible(true);
            sistema.setAreaPorGeoloc(true);
        }
        else{
            formSeleccionarArea.setVisible(true);
            sistema.setAreaPorGeoloc(false);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnAgregarAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarAreaActionPerformed
        // TODO add your handling code here:
        sistema.agregarCoordenadaAreaRiesgo(cboEdificio.getSelectedItem().toString());
        sistema.agregarCoordenadaAreaRiesgo(cboPlanta.getSelectedItem().toString());
        sistema.agregarCoordenadaAreaRiesgo(cboSector.getSelectedItem().toString());
        sistema.agregarCoordenadaAreaRiesgo(cboOrientacion.getSelectedItem().toString());
        cboEdificio.setSelectedIndex(0);
        cboPlanta.setSelectedIndex(0);
        cboSector.setSelectedIndex(0);
        cboOrientacion.setSelectedIndex(0);
        JOptionPane.showMessageDialog(null, "Se cargó correctamente el are de riesgo predefinida","Informacion",JOptionPane.INFORMATION_MESSAGE);
        this.formSeleccionarArea.setVisible(false);
    }//GEN-LAST:event_btnAgregarAreaActionPerformed

    private void txtTotalInvolucradosFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtTotalInvolucradosFocusLost
        // TODO add your handling code here:
        int maximo = Integer.parseInt(txtTotalInvolucrados.getText());
        SpinnerNumberModel model = new SpinnerNumberModel(1, 1, maximo, 1);
        
        //model.setMinimum(1);
        //model.setMaximum(Integer.parseInt(txtTotalInvolucrados.getText()));
        //spinnerTotallnvolucrados.setModel(model);
        jSpinner2.setModel(model);
    }//GEN-LAST:event_txtTotalInvolucradosFocusLost

    private void btnCancelarAltaAreaRiesgoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarAltaAreaRiesgoActionPerformed
        // TODO add your handling code here:
        sistema.vaciarCoordenadasAreaRiesgo();
        limpiarAltaAreaDeRiesgo();
    }//GEN-LAST:event_btnCancelarAltaAreaRiesgoActionPerformed

    /**
     * @param args the command line arguments
     */
    private static Sistema sistema;
    
    public static void main(String args[]) {
        
        sistema = new Sistema();
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SGAR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SGAR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SGAR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SGAR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new SGAR().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(SGAR.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        });
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarArea;
    private javax.swing.JButton btnAgregarF;
    private javax.swing.JButton btnAgregarFactorRiesgo;
    private javax.swing.JButton btnCancelarAltaAreaRiesgo;
    private javax.swing.JButton btnConfirmarImpacto;
    private javax.swing.JButton btnGuardarAccidente;
    private javax.swing.JButton btnGuardarAreaRiesgo;
    private javax.swing.JComboBox cboAreaRiesgo;
    private javax.swing.JComboBox cboEdificio;
    private javax.swing.JComboBox cboFactorDeRiesgo;
    private javax.swing.JComboBox cboImpacto;
    private javax.swing.JComboBox cboNivelCapacitacion;
    private javax.swing.JComboBox cboOrientacion;
    private javax.swing.JComboBox cboPlanta;
    private javax.swing.JComboBox cboSector;
    private javax.swing.JInternalFrame formAgregarFactoresRiesgo;
    private javax.swing.JInternalFrame formSeleccionarArea;
    private javax.swing.JFormattedTextField ftxtFechaAccidente;
    private javax.swing.JFormattedTextField ftxtHoraAccidente;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner jSpinner2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel jpInvolucrados;
    private javax.swing.JLabel lblAreaRiesgo;
    private javax.swing.JLabel lblFactorDeRiesgo;
    private javax.swing.JLabel lblFechaAccidente;
    private javax.swing.JLabel lblHS;
    private javax.swing.JLabel lblHoraAccidente;
    private javax.swing.JLabel lblIdAccidente;
    private javax.swing.JLabel lblIdArea;
    private javax.swing.JLabel lblImpacto;
    private javax.swing.JLabel lblInvolucrados;
    private javax.swing.JLabel lblNivelCapacitacion;
    private javax.swing.JLabel lblNombreArea;
    private javax.swing.JLabel lblTotalInvolucrados;
    private javax.swing.JList lstFactoresRiesgo;
    private javax.swing.JPanel panelAltaAccidente;
    private javax.swing.JPanel panelAltaAreaRiesgo;
    private javax.swing.JPanel panelDescrFactor;
    private javax.swing.JTextArea txtAreaDescr;
    private javax.swing.JTextField txtIdAccidente;
    private javax.swing.JTextField txtIdArea;
    private javax.swing.JTextField txtNombreArea;
    private javax.swing.JTextField txtTotalInvolucrados;
    // End of variables declaration//GEN-END:variables

    
}
